var Mytellphone = "";
window.onload = function(){
    var myChart = echarts.init(document.getElementById('main'),'macarons');

    // 指定图表的配置项和数据
    var option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [
            {
                type: 'category',
                data: [],
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '收益',
                type: 'bar',
                barWidth: '60%',
                data: []
            }
        ]
    };

    var myChart1 = echarts.init(document.getElementById('main1'),'macarons');

    // 指定图表的配置项和数据
    var option1 = {
        tooltip: {
            trigger: 'item'
        },
        legend: {
            top: '5%',
            left: 'center'
        },
        series: [
            {
                name: '收益占比',
                type: 'pie',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                itemStyle: {
                    borderRadius: 10,
                    borderColor: '#fff',
                    borderWidth: 2
                },
                label: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    label: {
                        show: true,
                        fontSize: '40',
                        fontWeight: 'bold'
                    }
                },
                labelLine: {
                    show: false
                },
                data: [
                    {value:'', name: '普通用户'},
                    {value:'', name: '会员用户'}
                ]
            }
        ]
    };


    axios.post("http://localhost:8081/user/common").then(res => {
        var username = document.getElementById("username");
        var username2 = document.getElementById("username2");
        var RegistrationTime = document.getElementById("RegistrationTime");
        if(res.data.state){
            var admin = res.data.admin;
            username.innerText = admin.username;
            username2.value = admin.username;
            Mytellphone = admin.tellphone;
            RegistrationTime.value = admin.registtime;

        }
    });
    axios.post("http://localhost:8081/admin/weekProfit").then(res => {
        if(res.data.state){
            option.xAxis[0].data = res.data.weeks;
            option.series[0].data = res.data.result;
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }
    });
    axios.post("http://localhost:8081/admin/weekProfit2").then(res => {
        if(res.data.state){
            option1.series[0].data[0].value = res.data.userProfit;
            option1.series[0].data[1].value = res.data.memberProfit;
            // 使用刚指定的配置项和数据显示图表。
            myChart1.setOption(option1);
        }
    });
    axios.post("http://localhost:8081/admin/todayProfit").then(res => {
        if(res.data.state){
            document.getElementById("day").innerText = res.data.today;
            document.getElementById("profit").innerText = res.data.result;
        }
    });
}
function Ipone() {
	//手机号验证
	const telephone = document.getElementById("telephone").value;
	const reg1 =/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;
	if (!reg1.test(telephone)) {
		phone.innerHTML="<img src='../img/no.png' style='vertical-align: middle;'>";
	}
	else {
		phone.innerHTML = "<img src='../img/yes.png' style='vertical-align: middle;'>";
	}
}
function npd(){
	const newpassword = document.getElementById("newpassword").value;
	const reg2 = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*.])[a-zA-Z\d#@!~%^&*.]{6,}$/;
	if (!reg2.test(newpassword)){
		nepd.innerHTML="<img src='../img/no.png' style='vertical-align: middle;'>";
		// nepd.innerHTML="<span style='color: red'>请输入正确格式的密码！</span>";

	}
	else {
		nepd.innerHTML = "<img src='../img/yes.png' style='vertical-align: middle;'>";
	}
}
function opd(){
	const npdd = document.getElementById("newpassword").value;
	const againpassword = document.getElementById("againpassword").value;
	if (againpassword != npdd ){
		oepd.innerHTML="<img src='../img/no.png'  style='vertical-align: middle;'>";
	}
	else{
		oepd.innerHTML="<img src='../img/yes.png' style='vertical-align: middle;'>";
	}
}
function sub(){
    const telp = document.getElementById("telephone").value;
	const aspd = document.getElementById("againpassword").value;
    const nspd = document.getElementById("newpassword").value;
    const reg2 = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*.])[a-zA-Z\d#@!~%^&*.]{6,}$/;

    if(telp == ''||aspd == ''||nspd == ''){
        alert('请补全信息！');
        return false;
    }else if(!reg2.test(nspd)){
        alert("密码格式不对，请检查！");
    }
    else if(aspd != nspd){
        alert('两次密码不同,请检查！');
        return false;
    }
    else if(telp != Mytellphone){   //需要与数据库电话绑定
        alert('与默认电话不同，请重新输入！')
        return false;
    }
    else {
        var flag = confirm("确定提交？");
        if(flag){
            axios.post("http://localhost:8081/admin/modifyPassword",{password:aspd}).then(res => {
                if(res.data.state){
                    alert(res.data.msg);
                    location.href = "../html/login.html";
                }else{
                    alert(res.data.msg);
                }
            })
        }
    }
}
